package com.wnhz.work.yz.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
import android.widget.TextView;
import com.wnhz.work.yz.BaseActivity;
import com.wnhz.work.yz.R;
import com.wnhz.work.yz.adapter.Look2Adapter;
import com.wnhz.work.yz.bean.Finish1;
import com.wnhz.work.yz.bean.LookDetailsBean;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

public class LookDetials2Activity extends BaseActivity implements View.OnClickListener {
    private static final String TAG = "LookDetials2Activity";
    private ListView my_listView;
    private LookDetailsBean bean;
    private TextView tv_all_price;
    private Look2Adapter adapter;
    private String skuId;
    private String type;

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onEventMainThread(Finish1 event) {
        finish();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_look_detials2);
        EventBus.getDefault().register(this);
        initTilte();
        intData();
        initView();
    }

    @Override
    protected void onDestroy() {
        EventBus.getDefault().unregister(this);
        super.onDestroy();
    }

    private void intData() {
        bean = (LookDetailsBean) getIntent().getSerializableExtra("data");
        type = getIntent().getStringExtra("type");
        skuId = getIntent().getStringExtra("sku_id");
        my_listView = (ListView) findViewById(R.id.my_listView);
        tv_all_price = (TextView) findViewById(R.id.tv_all_price);

    }

    private void initView() {
        double oprice = Double.parseDouble(bean.getInfo().getOprice());
        if (oprice == 0.0){
            tv_all_price.setText(bean.getInfo().getTotal_price() + "");
        }else{
            tv_all_price.setText(bean.getInfo().getOprice() + "");
        }
        adapter = new Look2Adapter(LookDetials2Activity.this, bean.getInfo().getCate_info());
        my_listView.setAdapter(adapter);
    }

    private void initTilte() {
        TextView title = (TextView) findViewById(R.id.view_main_middle_title);
        title.setText("单间配置");
        findViewById(R.id.btn_main_left).setOnClickListener(this);
        findViewById(R.id.btn_main_right).setOnClickListener(this);
        TextView right = (TextView) findViewById(R.id.tv_right);
        right.setText("下一步");
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_main_left:
                finish();
                break;
            //下一步
            case R.id.btn_main_right:
                Intent intent = new Intent(this, AddCart2Activity.class);
                intent.putExtra("packageId", bean.getInfo().getPackage_id());
                intent.putExtra("skuId", skuId);
                intent.putExtra("money", bean.getInfo().getOprice());
                intent.putExtra("type", "" + type);
                startActivity(intent);
                break;
        }
    }
}
